#!/bin/bash

echo '安装docker'
docker -v
if [ $? -eq  0 ]; then
  echo 'docker已安装'
else
  yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate \
      docker-logrotate docket-engine -y
    yum install -y yum-utils
    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    yum install -y docker-ce docker-ce-cli containerd.io
    systemctl start docker
    docker version
    systemctl enable docker
fi

echo '安装docker-compose'
docker-compose --version
if [ $? -eq  0 ]; then
  echo 'docker-compose 已安装'
else
  # 下载 Docker-Compose 的当前稳定版本
  #curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  wget https://childsong.oss-cn-beijing.aliyuncs.com/java-environment/docker-compose-2.2.2
  mv docker-compose-2.2.2 /usr/local/bin/docker-compose
  # 将可执行权限应用于二进制文件
  ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  chmod +x /usr/local/bin/docker-compose
  docker-compose --version
fi

echo '安装java'
yum install -y java-devel
#!/bin/bash
if type -p java; then
    echo "Java has been installed."
else
#  wget -c https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-x64.tar.gz;
  wget https://childsong.oss-cn-beijing.aliyuncs.com/java-environment/jdk-8u181-linux-x64.tar.gz
  tar -zxvf ./jdk-8u181-linux-x64.tar.gz -C /usr/local/
  mv /usr/local/jdk1.8.0_181  /usr/local/javaJDK
  echo "JAVA_HOME=/usr/local/javaJDK
  PATH=\$JAVA_HOME/bin:\$PATH
  CLASSPATH=\$JAVA_HOME/jre/lib/ext:\$JAVA_HOME/lib/tools.jar
  export PATH JAVA_HOME CLASSPATH" >> /etc/profile
  source /etc/profile
  echo "setting path successful."
  java -version
  echo "installed successful."
fi

echo '安装Node.js16'
node --version
if [ $? -eq  0 ]; then
  echo 'Node.js 已安装'
else
  wget https://childsong.oss-cn-beijing.aliyuncs.com/java-environment/node-v16.16.0-linux-x64.tar.xz
  tar -xvf node-v16.16.0-linux-x64.tar.xz
  rm -rf node-v16.16.0-linux-x64.tar.xz
  mv -f node-v16.16.0-linux-x64 /usr/local/bin/nodejs
  echo "# nodejs env" >> /etc/profile
  echo "export PATH=/usr/local/bin/nodejs/bin:\$PATH" >> /etc/profile
  source /etc/profile
  node --version
fi

echo '安装maven'
mvn -version
if [ $? -eq  0 ]; then
  echo 'Maven 已安装'
else
  wget https://childsong.oss-cn-beijing.aliyuncs.com/java-environment/apache-maven-3.8.6.tar.gz
  echo "解压缩到指定目录"
  tar -zxv -f apache-maven-3.8.6.tar.gz
  rm -rf apache-maven-3.8.6.tar.gz
  mv -f apache-maven-3.8.6 /usr/local/bin/apache-maven
  echo "# maven env" >> /etc/profile
  echo "export PATH=/usr/local/bin/apache-maven/bin:\$PATH" >> /etc/profile
  mvn -version
  source /etc/profile
fi

echo "java 环境初始化完成"